package org.example.admin.service;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.example.db.entity.User;
import org.example.db.entity.UserRole;
import org.example.db.entity.WxUserRole;
import org.example.db.mapper.WxUserRoleMapper;
import org.example.security.service.UserRoleService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class AdminUserRoleService {

    UserRoleService userRoleService;
    WxUserRoleMapper wxUserRoleMapper;

    public AdminUserRoleService(UserRoleService userRoleService, WxUserRoleMapper wxUserRoleMapper) {
        this.userRoleService = userRoleService;
        this.wxUserRoleMapper = wxUserRoleMapper;
    }

    public List<Long> getUserIdListByRoleId(Long roleId){

        List<UserRole> userRoleByRoleId = userRoleService.getUserRoleByRoleId(roleId);
        List<WxUserRole> wxUserRoles = wxUserRoleMapper.selectList(Wrappers.lambdaQuery(WxUserRole.class).eq(WxUserRole::getRoleId, roleId));
        ArrayList<Long> userIdList = new ArrayList<>();
        for(UserRole userRole: userRoleByRoleId){
            userIdList.add(userRole.getUserId());
        }
        for(WxUserRole wxUserRole: wxUserRoles){
            userIdList.add(wxUserRole.getWxUserId());
        }
        return userIdList;
    }
}
